#include <libpmem.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
const int PMEM_LEN = 1024 * 1024;

int main() {
    char *pmemaddr;  //文件的内存映射地址
    int is_pmem;
    const char * map_file = "pmem_mmap_file";
    size_t mapped_len;

    if ((pmemaddr = (char*)pmem_map_file(map_file, PMEM_LEN, PMEM_FILE_CREATE|PMEM_FILE_EXCL, 0666, &mapped_len, &is_pmem)) == NULL) {
		perror("pmem_map_file");
		exit(1);
	}

    if (PMEM_LEN != mapped_len) {
       fprintf(stderr, "Error: cannot map %d bytes\n", PMEM_LEN);
       pmem_unmap(pmemaddr, mapped_len);
       exit(1);
    }
    strcpy(pmemaddr, "hello, persistent memory");

    if (is_pmem) {
		pmem_persist(pmemaddr, mapped_len);
	} else {
		pmem_msync(pmemaddr, mapped_len);
	}
    pmem_unmap(pmemaddr, mapped_len);

    return 0;
}